<template>
  <div class="reportModel">
    <zyModel :title="title" :show="show" width="1200" @close="close" @submit="submit">
      <div class="model-table-box">
        <!--    列表-->
        <div class="tableBox" :loading="loading">
          <div class="pageTitle">
            <div class="title">{{pageTitle}}</div>
            <zy-button @click="addTr" :disabled="parseFloat(list[list.length - 1].end_score) >= 100">
              加行
            </zy-button>
          </div>
          <div class="head tr">
            <div class="index">序号</div>
            <div class="interval">月度处理可疑件数量</div>
            <div class="interval">季度处理可疑件数量</div>
            <div class="resource">评估结果</div>
            <div class="btnArea">操作</div>
          </div>
          <div class="tr" v-for="(item,index) in list" :key="index">
            <div class="index">{{index+1}}</div>
            <div class="interval">
              <zy-input v-model="item.month_start_num" size="mini" type="invoiceNumber" disabled></zy-input>
              <span class="unit"> ≤ X < </span>
              <zy-input v-model="item.month_end_num" size="mini" type="invoiceNumber"
                        :disabled="index < list.length-1"></zy-input>
              <span class="unit">件</span>
            </div>
            <div class="interval">
              <zy-input v-model="item.quarter_start_num" size="mini" type="invoiceNumber" disabled></zy-input>
              <span class="unit"> ≤ X < </span>
              <zy-input v-model="item.quarter_end_num" size="mini" type="invoiceNumber"
                        :disabled="index < list.length-1"></zy-input>
              <span class="unit">件</span>
            </div>
            <div class="resource">
              <zy-input v-model="item.result" :disabled="index < list.length-1"></zy-input>
            </div>
            <div class="btnArea">
              <zy-button text-button mini v-if="index==list.length-1" @click="clear">清空</zy-button>
              <zy-button text-button mini type="danger" class="delBtn" v-if="index==list.length-1"
                         @click="deleted(index)">删除
              </zy-button>
            </div>
          </div>
        </div>
        <div class="form">
          <div class="pageTitle">
            <div class="title">分析评估频率</div>
          </div>
          <el-checkbox v-model="is_month">月度分析评估</el-checkbox>
          <el-checkbox v-model="is_quarter">季度分析评估</el-checkbox>
        </div>
      </div>
    </zyModel>
  </div>
</template>

<script>
	export default {
		name: "reportModel",
		props: {
			show: {
				type: Boolean,
				default: () => false
			},
			modelType: {
				type: String,
				default: () => ''
			}
		},
		data() {
			return {
				title: '',
				pageTitle: '',
				loading: false,
				list: [{
					month_start_num: 0,
					month_end_num: '',
					quarter_start_num: 0,
					quarter_end_num: '',
					result: "",
				}],
				is_month: false,
				is_quarter: false
			};
		},
		computed: {},
		watch: {
			show(newVal) {
				if (newVal)
					this.getData();
			},
			modelType(newVal) {
				switch (newVal) {
					case '1':
						this.title = '物流企业分析评估设置';
						this.pageTitle = '分析评估等级'
						break;
					case '2':
						this.title = '合作站点分析评估设置';
						this.pageTitle = '分析评估等级'
						break;
					case '3':
						this.title = '从业人员分析评估设置';
						this.pageTitle = '分析评估等级'
						break;
					case '4':
						this.title = '监管辖区分析评估设置';
						this.pageTitle = '分析评估等级'
						break;
					case '5':
						this.title = '监管民警处理数据设置';
						this.pageTitle = '处理数据评估等级'
						break;
				}
			}
		},
		components: {},
		methods: {
			close() {
				this.$emit('close')
			},
			submit() {
				let postData = {
					type: this.modelType
				}, analysis_settings_list = JSON.parse(JSON.stringify(this.list)), num = 0;
				if (this.is_month) num = 1;
				if (this.is_quarter) num = 1;
				if (num == 0)
					return this.$message.error('请勾选月度分析评估或季度分析评估')
				postData['analysis_settings_list'] = analysis_settings_list.filter(item => {
					item.is_month = this.is_month ? '1' : '0';
					item.is_quarter = this.is_quarter ? '1' : '0';
					item.type = this.modelType;
					return item;
				})
				this.$axios.post(this.$api.g_setAnalysis, {...postData}).then(res => {
					let {code, msg, data} = res;
					console.log(132213321)
					if (code == 200) {
						this.$message.success('提交成功!');
						this.close()
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			addTr() {
				let list = JSON.parse(JSON.stringify(this.list)),
					item = list[list.length - 1];
				if (!item.month_end_num.length || parseFloat(item.month_end_num) < parseFloat(item.month_start_num))
					return this.$message.error('请重新设置月度处理可疑件数量')
				if (!item.quarter_end_num.length || parseFloat(item.quarter_end_num) < parseFloat(item.quarter_start_num))
					return this.$message.error('请重新设置月度处理可疑件数量')
				this.list.push({
					month_start_num: list[list.length - 1].month_end_num || 0,
					month_end_num: '',
					quarter_start_num: list[list.length - 1].quarter_end_num || 0,
					quarter_end_num: '',
					result: "",
				})
			},
			clear() {
				let list = JSON.parse(JSON.stringify(this.list));
				if (this.list.length > 1) {
					this.list = list.filter((item, index) => {
						if (index == list.length - 1) {
							item.month_start_num = list[list.length - 2].month_end_num || 0;
							item.month_end_num = ''
							item.quarter_start_num = list[list.length - 2].quarter_end_num || 0
							item.quarter_end_num = ''
							item.result = ""
						}
						return item;
					})
				} else {
					this.list = [{
						month_start_num: 0,
						month_end_num: '',
						quarter_start_num: 0,
						quarter_end_num: '',
						result: "",
					}]
				}
			},
			deleted(index) {
				if (index > 0)
					this.list.splice(index, 1)
			},
			getData() {
				this.$axios.post(this.$api.g_getAnalysis, {type: this.modelType}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						if (data && data.length) {
							this.list = data;
							this.is_month = data[0].is_month == 1
							this.is_quarter = data[0].is_quarter == 1
						} else {
							this.list = [{
								month_start_num: 0,
								month_end_num: '',
								quarter_start_num: 0,
								quarter_end_num: '',
								result: "",
							}]
							this.is_month = false
							this.is_quarter = false
						}
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					console.log(ret)
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
		},
		mounted() {
		},
		created() {
		}
	}
</script>

<style scoped lang="less">
  @import "../../../../style/common/common";

  @FAgentBgColor: #F5F7F8;
  @FAgentHoverBgColor: rgba(245, 247, 248, 0.6);
  @rateBorderColor: rgba(187, 185, 199, 0.19);

  .model-table-box {
    .tableBox {
      .pageTitle {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        margin-bottom: 10px;

        .title {
          line-height: 20px;
          font-size: 16px;
          font-weight: bold;
        }
      }

      .pageTitle::after {
        content: '';
        position: absolute;
        top: 8px;
        bottom: 8px;
        left: -12px;
        width: 4px;
        background: @allWarringColor;
      }

      .tr {
        display: flex;
        align-items: center;
        padding: 16px 0;
        border-bottom: 1px solid @rateBorderColor;

        &.head {
          color: @fontGrayColor;

          .interval, .color, .dubious, .early_type, .police_ids {
            // border-right: 1px solid @rateBorderColor;
          }
        }

        &:nth-child(2n) {
          background: @FAgentBgColor;
        }

        &:hover {
          background: @FAgentHoverBgColor;
        }

        .index {
          flex: 0 0 48px;
          display: flex;
          justify-content: center;
          align-items: center;
          border-right: 1px solid @rateBorderColor;
        }


        .interval, .resource {
          display: flex;
          justify-content: center;
          align-items: center;
          padding: 0 12px;

          &.interval {
            flex: 1;

            .unit {
              margin: 4px;
              font-size: 12px;
              flex: 0 0 40px;
            }
          }

          &.resource {
            flex: 1;
          }

        }

        .btnArea {
          flex: 0 0 100px;
          display: flex;
          align-items: center;

          .delBtn {
            margin-left: 8px;
          }
        }
      }
    }

    .form {
      .pageTitle {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        margin: 12px 0;
        height: 40px;

        .title {
          line-height: 20px;
          font-size: 16px;
          font-weight: bold;
        }
      }

      .pageTitle::after {
        content: '';
        position: absolute;
        top: 8px;
        bottom: 8px;
        left: -12px;
        width: 4px;
        background: @allWarringColor;
      }

      .el-checkbox {
        margin-right: 40px;
      }
    }
  }
</style>
